package com.daodao.daodaoschedule.infrastructure.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.daodao.daodaoschedule.domain.wechat.WechatAccount;
import com.daodao.daodaoschedule.infrastructure.dao.entity.WechatAccountPO;
import com.daodao.daodaoschedule.infrastructure.dao.mapper.WechatAccountMapper;
import com.daodao.daodaoschedule.infrastructure.repository.WechatAccountRepository;
import com.daodao.daodaoschedule.infrastructure.util.BeanCopyUtils;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Repository;

/**
 * @author mal
 * @date 2023-02-15 14:37
 */
@Repository
@AllArgsConstructor

public class WechatAccountRepositoryImpl implements WechatAccountRepository {

    private WechatAccountMapper wechatAccountMapper;



    @Override
    public void updateAccount(WechatAccount wechatAccount) {
        WechatAccountPO wechatAccountPO = BeanCopyUtils.copyBean(wechatAccount, WechatAccountPO.class);
        wechatAccountMapper.updateById(wechatAccountPO);
    }

    @Override
    public WechatAccount getByAccountId(Long accountId) {
        WechatAccountPO wechatAccountPO = wechatAccountMapper.selectOne(new LambdaQueryWrapper<WechatAccountPO>().eq(accountId != null, WechatAccountPO::getId, accountId));
        return BeanCopyUtils.copyBean(wechatAccountPO, WechatAccount.class);
    }
}
